﻿<%@ WebHandler Language="C#" Class="xinxi_qita" %>

using System;
using System.Web;
using System.Data;
using KeaoBase;
using KeaoDataBase;
using Newtonsoft.Json;
using System.Configuration;
using System.Collections.Generic;

public class xinxi_qita : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        try
        {
            string uid = context.Request.Form["uid"];
            string kid = context.Request.Form["kid"];
            if (!Auth.UserLogined(uid, kid))
            {
                context.Response.Write("请重试...");
                return;
            }
            string requestType =string.Format("{0}" ,context.Request.Form["requestType"]);
            string biaoDuanLeiXing =string.Format("{0}",context.Request.Form["qitaLeiXing"]);
            string zhandian = string.Format("{0}", context.Request.Form["zhandian"]);
            if (string.IsNullOrEmpty(requestType) || string.IsNullOrEmpty(biaoDuanLeiXing))
            {
                context.Response.Write("请重试...");
                return;
            }

            BaseDataBase m_DB = System.Reflection.Assembly.Load("KeaoDataBase").CreateInstance(string.Format("KeaoDataBase.{0}", ConfigurationManager.AppSettings["数据库类型"])) as BaseDataBase;
            if (!m_DB.InitDataBase(ConfigurationManager.ConnectionStrings["DataSource"].ConnectionString))
            {
                context.Response.Write("请重试...");
                return;
            }
            else
            {
                switch (requestType)
                {
                    case "1":
                        string searchCondition = m_DB.CreateAndCondition("biaoduanleixing", DataValueCommonType.字符串, biaoDuanLeiXing, "", SearchConditionType.等于);
                        searchCondition += m_DB.CreateAndCondition("zhandian", DataValueCommonType.字符串, zhandian, "", SearchConditionType.等于);
                        DataTable Dt = m_DB.GetDataTableByCondition("tbl_biaoduan", searchCondition);
                        string jsonStr = JsonConvert.SerializeObject(Dt);
                        context.Response.Write(jsonStr);
                        break;
                    case "2":
                        string biaoduanmingcheng = context.Request.Form["qitamingcheng"];
                        string biaoDuanID = context.Request.Form["qitaID"];
                        if (string.IsNullOrEmpty(biaoDuanID))
                        {
                            //新增
                            TableRow newRow = new TableRow("tbl_biaoduan", Guid.NewGuid().ToString(), DBCtl.插入);
                            TableCol col1 = new TableCol();
                            col1.ColName = "biaoduanmingcheng";
                            col1.ValueMember = biaoduanmingcheng;
                            col1.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col1);
                            TableCol col2 = new TableCol();
                            col2.ColName = "biaoduanleixing";
                            col2.ValueMember = biaoDuanLeiXing;
                            col2.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col2);
                            TableCol col3 = new TableCol();
                            col3.ColName = "shangchuanzhuangtai";
                            col3.ValueMember = "1";
                            col3.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col3);
                            TableCol col4 = new TableCol();
                            col4.ColName = "zhandian";
                            col4.ValueMember = zhandian;
                            col4.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col4);
                            TableCol col5 = new TableCol();
                            col5.ColName = "kehubianhao";
                            col5.ValueMember = ConfigurationManager.AppSettings["客户编号"];
                            col5.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col5);
                            if (m_DB.SaveTableRows(newRow) > 0)
                            {
                                context.Response.Write("OK");
                            }
                            else
                            {
                                context.Response.Write("Failed");
                            }
                        }
                        else
                        {
                            //修改 
                            TableRow newRow = new TableRow("tbl_biaoduan", biaoDuanID, DBCtl.修改);
                            TableCol col1 = new TableCol();
                            col1.ColName = "biaoduanmingcheng";
                            col1.ValueMember = biaoduanmingcheng;
                            col1.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col1);
                            TableCol col2 = new TableCol();
                            col2.ColName = "biaoduanleixing";
                            col2.ValueMember = biaoDuanLeiXing;
                            col2.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col2);
                            TableCol col3 = new TableCol();
                            col3.ColName = "shangchuanzhuangtai";
                            col3.ValueMember = "1";
                            col3.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col3);
                            TableCol col4 = new TableCol();
                            col4.ColName = "zhandian";
                            col4.ValueMember = zhandian;
                            col4.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col4);
                            TableCol col5 = new TableCol();
                            col5.ColName = "kehubianhao";
                            col5.ValueMember = ConfigurationManager.AppSettings["客户编号"];
                            col5.ValueType = DataValueCommonType.字符串;
                            newRow.DataCols.Add(col5);
                            if (m_DB.SaveTableRows(newRow) > 0)
                            {
                                context.Response.Write("OK");
                            }
                            else
                            {
                                context.Response.Write("Failed");
                            }
                        }
                        break;
                    case "3":
                        string delBiaoDuanID = context.Request.Form["qitaID"];
                        if (string.IsNullOrEmpty(delBiaoDuanID))
                        {
                            context.Response.Write("没有找到对应信息，请重试...");
                            return;
                        }
                        TableRow delRow = new TableRow();
                        delRow.TableName = "tbl_biaoduan";
                        delRow.ID = delBiaoDuanID;
                        if (m_DB.DeleteRowByID(delRow) > 0)
                        {
                            context.Response.Write("OK");
                        }
                        else
                        {
                            context.Response.Write("Failed");
                        }
                        break;
                }
            }
        }
        catch (Exception err)
        {
            KeaoUtils.LogTxt(string.Format("物资其他去向异常。{0}", err.Message));
            context.Response.Write("请重试...");
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}